package cn.com.hori.cms.controller;

import cn.com.hori.cms.entities.AdminToken;
import cn.com.hori.cms.model.CommonResponse;
import cn.com.hori.cms.service.ManagerService;
import cn.com.hori.cms.model.LoginInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 管理员相关
 *
 * @author 刘艺
 * @date 2018/3/8 11:42
 */
@RestController
@RequestMapping("/smc/manager")
public class ManagerController {
    private static Logger logger = LoggerFactory.getLogger(ManagerController.class);

    /**
     * 管理员 数据处理 服务
     */
    @Autowired
    private ManagerService managerService;

    /**
     * 登录页面提交登录表单
     *
     * @param loginInfo 被提交的表单信息封装的对象
     * @return 返回登录结果封装的对象
     */
    @PostMapping("/loginSubmit")
    public CommonResponse loginSubmit(@RequestBody LoginInfo loginInfo) {
        AdminToken token = managerService.loginSubmit(loginInfo);
        if (token == null) {
            return new CommonResponse<>(CommonResponse.LOGIN_FAIL_CODE, CommonResponse.LOGIN_FAIL_MSG);
        } else {
            return new CommonResponse<>(token);
        }
    }
}
